package com.koron.ticket.line.work.powerlinefirst.controller;

import com.koron.bean.base.Response;
import com.koron.bean.workflow.SubmitterParam;
import com.koron.bean.workflow.WorkflowUser;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.ticket.line.work.workticket.service.WorkTicketService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController("linePowerLineFirstWorkflowController")
@RequestMapping("lineWork/powerlinefirst/workflow")
public class PowerLineFirstWorkflowController {

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @Autowired
    private WorkTicketService lineWorkTicketService;

    @PostMapping("/draftwrite/handler")
    public Response<List<WorkflowUser>> draftwrite(@RequestBody SubmitterParam submitterParam) {
        return null;
    }

    @PostMapping("/callsign/handler")
    public Response<List<WorkflowUser>> callsign(@RequestBody SubmitterParam submitterParam) {
        List<WorkflowUser> list = lineWorkTicketService.getWorkflowUsers(submitterParam, null, 3);
        return Response.success(list);
    }

    @PostMapping("/callcountersign/handler")
    public Response<List<WorkflowUser>> callcountersign(@RequestBody SubmitterParam submitterParam) {
        //选择 会签人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, null, 3);
        List<WorkflowUser> list = lineWorkTicketService.getWorkflowUsers(submitterParam, null, 3);
        return Response.success(list);
    }

    @PostMapping("/callaccept/handler")
    public Response<List<WorkflowUser>> callacceptOper(@RequestBody SubmitterParam submitterParam) {
        //选择 接收人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, null, 1);
        List<WorkflowUser> list = lineWorkTicketService.getWorkflowUsers(submitterParam, null, 1);
        return Response.success(list);
    }

    @PostMapping("/callaccept/submitter")
    public Response<List<WorkflowUser>> callaccept(@RequestBody SubmitterParam submitterParam) {
        //选择 待许可人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, null, 1);
        List<WorkflowUser> list = lineWorkTicketService.getWorkflowUsers(submitterParam, null, 4);
        return Response.success(list);
    }

    @PostMapping("/callpermit/submitter")
    public Response<List<WorkflowUser>> callpermit(@RequestBody SubmitterParam submitterParam) {
        //选择 待工作终结人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, null, 1);
        List<WorkflowUser> list = lineWorkTicketService.getWorkflowUsers(submitterParam, null, 4);
        return Response.success(list);
    }

    @PostMapping("/callworkend/submitter")
    public Response<List<WorkflowUser>> callworkend(@RequestBody SubmitterParam submitterParam) {
        //选择 待工作票终结人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, null, 1);
        List<WorkflowUser> list = lineWorkTicketService.getWorkflowUsers(submitterParam, null, 4);
        return Response.success(list);
    }

}
